package com.time.admin.infra.basic.service.impl;

import com.time.admin.infra.basic.entity.Post;
import com.time.admin.infra.basic.mapper.PostDao;
import com.time.admin.infra.basic.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 文章表(Posts)表服务实现类
 *
 * @author HuangQi
 * @since 2025-09-30 16:57:20
 */
@Service("postService")
public class PostServiceImpl implements PostService {

    @Autowired
    private PostDao postsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param postId 主键
     * @return 实例对象
     */
    @Override
    public Post queryById(Long postId) {
        return this.postsDao.queryById(postId);
    }

    /**
     * 分页查询
     *
     * @param posts    筛选条件
     * @param start    起始位置
     * @param pageSize 分页大小
     * @return 查询结果
     */
    @Override
    public List<Post> pageQueryByCondition(Post posts, int start, int pageSize) {
        return this.postsDao.queryAllByLimit(posts, start, pageSize);
    }

    @Override
    public List<Post> pageQueryByCategoryId(Post post, Long categoryId, int start, int pageSize) {
        return this.postsDao.queryAllByCategoryId(post, categoryId, start, pageSize);
    }

    /**
     * 新增数据
     *
     * @param posts 实例对象
     * @return 实例对象
     */
    @Override
    public Integer insert(Post post) {
        return this.postsDao.insert(post);
    }

    /**
     * 修改数据
     *
     * @param posts 实例对象
     * @return 实例对象
     */
    @Override
    public Integer update(Post post) {
        return this.postsDao.update(post);
    }

    /**
     * 通过主键删除数据
     *
     * @param postId 主键
     * @return 是否成功
     */
    @Override
    public Integer deleteById(Long postId) {
        return this.postsDao.deleteById(postId);
    }

    @Override
    public Integer count(Post post) {
        return Math.toIntExact(this.postsDao.count(post));
    }

    @Override
    public Integer countByCondition(Post post) {
        return this.postsDao.countByCondition(post);
    }

    @Override
    public Integer countByCategoryId(Post post, Long categoryId) {
        return this.postsDao.countByCategoryId(post, categoryId);
    }
}
